#usr/bin/python


import re


"""
17.026549	H3N	NH3
18.010564	H2O	Water
18.010564	H2O	H2O
22.989769	Na	Sodium
24.018743	HLiO	Lithium hydroxide
26.015650	C2H2	Acetylene
27.010899	CHN	Cyanide
28.006148	N2	Nitrogen
28.031300	C2H4	Ethylene
"""

class met_jp_parser:
	
	def __init__(self, config_file):
		self.data =config_file
	
	def parsing(self):
		#use regex : faster
		regx =re.compile('(.+)\t(.+)\t(.+)\n')
		lst =[]
		with open(self.data) as f:
			l =f.readline()
			while l != "" :
				if regx.match(l):
					dico ={}
					dico["MASS"] = regx.match(l).group(1)
					dico["FORMULA"] =regx.match(l).group(2)
					dico["NAME"] =regx.match(l).group(3)
					#return dico
					lst.append(dico)
				l =f.readline()
			return lst

if __name__=="__main__":
	p =met_jp_parser("..\config\metaboliteMass.txt")
	l =p.parsing("C13H12O8")
	for d in l.values():
		print d
		